package fr.umlv.m2.jee.spij.persistence.schooling;

import fr.umlv.m2.jee.spij.persistence.education.Unit;
import org.hibernate.annotations.Columns;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;
import org.joda.time.Interval;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Class Registration
 *
 * @author lounes
 */
@Entity
@Table(name = "REG_REGISTRATION")
public class Registration implements Serializable {

    /**
     * the primary key.
     */
    @Id
    @Column(name = "REG_ID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    /**
     *
     */
    @Column(name = "REG_STUDENT_LOGIN")
    private String login;

    /**
     *
     */
    @Columns(columns = {@Column(name = "REG_START_YEAR"),
            @Column(name = "REG_END_YEAR")})
    @Type(type = "org.joda.time.contrib.hibernate.PersistentInterval")
    private Interval year;

    /**
     *
     */
    @Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
    @Column(name = "REG_DATE")
    private DateTime date;

    /**
     *
     */
    @Column(name = "REG_TRA_ID")
    private Long training;

    /**
     *
     */
    @Column(name = "REG_COU_ID")
    private Long course;

    /**
     *
     */
    @ManyToMany(cascade = {CascadeType.ALL})
    @JoinTable(name = "REG_AND_UNI", joinColumns = {@JoinColumn(name = "REG_ID", referencedColumnName = "REG_ID")}, inverseJoinColumns = {@JoinColumn(name = "UNI_ID", referencedColumnName = "UNI_ID")})
    private List<Unit> units = new ArrayList<Unit>();

    /**
     * @param id
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * @return
     */
    public long getId() {
        return id;
    }

    /**
     * @param year
     */
    public void setYear(Interval year) {
        this.year = year;
    }

    /**
     * @return
     */
    public Interval getYear() {
        return year;
    }

    /**
     * @param date
     */
    public void setDate(DateTime date) {
        this.date = date;
    }

    /**
     * @return
     */
    public DateTime getDate() {
        return date;
    }

    /**
     * @return the login
     */
    public String getLogin() {
        return login;
    }

    /**
     * @param login the login to set
     */
    public void setLogin(String login) {
        this.login = login;
    }

    /**
     * @param training the training to set
     */
    public void setTraining(Long training) {
        this.training = training;
    }

    /**
     * @return the training
     */
    public Long getTraining() {
        return training;
    }

    /**
     * @param units the units to set
     */
    public void setUnits(List<Unit> units) {
        this.units = units;
    }

    /**
     * @return the units
     */
    public List<Unit> getUnits() {
        return units;
    }

    /**
     * @param e
     *
     * @return
     *
     * @see java.util.List#add(java.lang.Object)
     */
    public boolean addUnit(Unit e) {
        return units.add(e);
    }

    /**
     * @param index
     *
     * @return
     *
     * @see java.util.List#get(int)
     */
    public Unit getUnit(int index) {
        return units.get(index);
    }

    /**
     * @param index
     *
     * @return
     *
     * @see java.util.List#remove(int)
     */
    public Unit removeUnit(int index) {
        return units.remove(index);
    }

    /**
     * @param course the course to set
     */
    public void setCourse(Long course) {
        this.course = course;
    }

    /**
     * @return the course
     */
    public Long getCourse() {
        return course;
    }

}
